﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DelonixRegiaHotel.Classes;
using DelonixRegiaHotel.DBManager;
using System.Collections;

namespace DelonixRegiaHotel
{
    public partial class AdvanceBookingForm : Form
    {
        string CheckID;
        string roomStatus;
        string customerID;
        public AdvanceBookingForm()
        {
            InitializeComponent();
        }

        private void btnNRIC_Click(object sender, EventArgs e)
        {
            Customer c = DelonixRegiaDB.getCustomerDetails(tbxCheckNRIC.Text);
            lblFirstName.Text = c.FirstName;
            lblLastName.Text = c.LastName;
            lblNRIC.Text = c.Nric;
            lblAddress.Text = c.HomeAddress;
            lblPostalCode.Text = Convert.ToString(c.PostalCode);
            lblCountry.Text = c.Country;
            lblDOB.Text = Convert.ToString(c.Dob);
            lblContactNo.Text = Convert.ToString(c.ContactNo);
            lblEmail.Text = c.Email;
            customerID = c.CustomerID;
            ArrayList temp = new ArrayList();
            cboxRoomNo.Items.Clear();
            temp = DelonixRegiaDB.getRoomNo(tbxCheckNRIC.Text);
            foreach (var v in temp)
            {
                if (v is CheckInOut)
                {
                    CheckInOut cio = new CheckInOut();
                    cio = (CheckInOut)v;
                    //         tbxRoomNo.Text = cio.RoomNo;
                    cboxRoomNo.Items.Add(cio.RoomNo);
                    //        tbxCheckID.Text = cio.CheckID;

                }
            }
            //ArrayList temp = new ArrayList();
            //temp = DelonixRegiaDB.getRoomNo(Convert.ToString(c.CustomerID));
            //foreach (var v in temp)
            //{
            //    if (v is CheckInOut)
            //    {
            //        CheckInOut cio = new CheckInOut();

            //        cboxRoomNo.Items.Add(cio.RoomNo);

            //    }
            //}



        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string roomNo = (string)cboxRoomNo.SelectedItem;
            CheckInOut cio = DelonixRegiaDB.getBookingDetails(roomNo);
            lblPaymentType.Text = cio.PaymentType;
            lblnumOfAdult.Text = Convert.ToString(cio.NumOfAdult);
            lblCheckOut.Text = Convert.ToString(cio.CheckOutTime.ToShortDateString());
            lblCheckInDate.Text = Convert.ToString(cio.CheckInTime.ToShortDateString());
            lblBalance.Text = Convert.ToString(cio.Balance);
            lblnumOfAdult.Text = Convert.ToString(cio.NumOfAdult);
            lblNumOfChild.Text = Convert.ToString(cio.NumOfChild);
            lblNumOfDay.Text = Convert.ToString(cio.NumOfDays);
            tbxRemark.Text = cio.Remarks;
            roomStatus = cio.RoomStatus;
            lblPaymentType.Text = cio.PaymentType;

            RoomType rt = DelonixRegiaDB.getRoomInformation(roomNo);
            lblRoomPrice.Text = Convert.ToString(rt.RoomPrice);
            lblRmNum.Text = roomNo;
            lblRmType.Text = rt.RoomTypeName;



        }

        private void btnCheckIn_Click(object sender, EventArgs e)
        {
            if (tbxNoOfKey.Text == string.Empty)
            {
                MessageBox.Show("Please enter the number of keys");
            }
            else
            {
                CheckInOut cio = new CheckInOut();
                cio.RoomStatus = "CheckIn";
                cio.NumOfKey = Convert.ToInt16(tbxNoOfKey.Text);
                if (DelonixRegiaDB.UpdateCheckInOut(cio) == 1)
                {
                    MessageBox.Show("Update Successful!");
                }
            }
        }//
    }
}
